package ro.unibuc.hobbygroups.domain.xml;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="groups")
public class GroupList {
	
	@XmlAttribute
	private String type = "array";
	
	@XmlAttribute
	private int count;
	
	List<Group> groups;
	
	/**
	 * This is when you don't have the list prepared
	 * 
	 */
	public GroupList() {
		super();
	}
	
	public GroupList(List<Group> groups) {
		this.groups = groups;
		this.count = groups.size();
	}
/*
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
*/
	@XmlElement(name="group")
	public List<Group> getGroups() {
		return groups;
	}
	
	public void setGroups(List<Group> groups) {
		this.groups = groups;
	}
	
	public static List<Group> fromDomain(List<ro.unibuc.hobbygroups.domain.Group> groups, String imageURL, String thumbnailURL) {
		List<Group> xmlGroups = new ArrayList<Group>(groups.size());
		for (int i = 0; i < groups.size(); i ++) {
			xmlGroups.add(Group.fromDomain(groups.get(i), imageURL, thumbnailURL));
		}
		
		return xmlGroups;
	}
}
